Clover coverage report - Enterprise Web Services - 1.0
Coverage timestamp: Mon May 30 2005 17:10:32 CEST
file stats: LOC: 897   Methods: 15
NCLOC: 707   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
J2eeStubWriter.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * Copyright 2001-2004 The Apache Software Foundation.
 3   
  * 
 4   
  * Licensed under the Apache License, Version 2.0 (the "License");
 5   
  * you may not use this file except in compliance with the License.
 6   
  * You may obtain a copy of the License at
 7   
  * 
 8   
  *      http://www.apache.org/licenses/LICENSE-2.0
 9   
  * 
 10   
  * Unless required by applicable law or agreed to in writing, software
 11   
  * distributed under the License is distributed on an "AS IS" BASIS,
 12   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
  * See the License for the specific language governing permissions and
 14   
  * limitations under the License.
 15   
  */
 16   
 package org.apache.geronimo.ews.jaxrpcmapping;
 17   
 
 18   
 import org.apache.axis.Constants;
 19   
 import org.apache.axis.constants.Style;
 20   
 import org.apache.axis.constants.Use;
 21   
 import org.apache.axis.utils.JavaUtils;
 22   
 import org.apache.axis.utils.Messages;
 23   
 import org.apache.axis.wsdl.symbolTable.BindingEntry;
 24   
 import org.apache.axis.wsdl.symbolTable.CollectionTE;
 25   
 import org.apache.axis.wsdl.symbolTable.DefinedType;
 26   
 import org.apache.axis.wsdl.symbolTable.Element;
 27   
 import org.apache.axis.wsdl.symbolTable.FaultInfo;
 28   
 import org.apache.axis.wsdl.symbolTable.MimeInfo;
 29   
 import org.apache.axis.wsdl.symbolTable.Parameter;
 30   
 import org.apache.axis.wsdl.symbolTable.Parameters;
 31   
 import org.apache.axis.wsdl.symbolTable.SymbolTable;
 32   
 import org.apache.axis.wsdl.symbolTable.TypeEntry;
 33   
 import org.apache.axis.wsdl.toJava.JavaClassWriter;
 34   
 import org.apache.axis.wsdl.toJava.Utils;
 35   
 
 36   
 import javax.wsdl.Binding;
 37   
 import javax.wsdl.BindingOperation;
 38   
 import javax.wsdl.Fault;
 39   
 import javax.wsdl.Message;
 40   
 import javax.wsdl.Operation;
 41   
 import javax.wsdl.OperationType;
 42   
 import javax.wsdl.Part;
 43   
 import javax.wsdl.PortType;
 44   
 import javax.wsdl.extensions.UnknownExtensibilityElement;
 45   
 import javax.wsdl.extensions.soap.SOAPBinding;
 46   
 import javax.wsdl.extensions.soap.SOAPOperation;
 47   
 import javax.xml.namespace.QName;
 48   
 import java.io.IOException;
 49   
 import java.io.PrintWriter;
 50   
 import java.util.ArrayList;
 51   
 import java.util.Collection;
 52   
 import java.util.HashMap;
 53   
 import java.util.HashSet;
 54   
 import java.util.Iterator;
 55   
 import java.util.List;
 56   
 import java.util.Map;
 57   
 import java.util.Vector;
 58   
 
 59   
 /**
 60   
  * This is Wsdl2java's stub writer.  It writes the <BindingName>Stub.java
 61   
  * file which contains the <bindingName>Stub class.
 62   
  *
 63   
  * @author Ias (iasandcb@tmax.co.kr)
 64   
  */
 65   
 public class J2eeStubWriter extends JavaClassWriter {
 66   
     private BindingEntry bEntry;
 67   
     private Binding binding;
 68   
     private SymbolTable symbolTable;
 69   
 
 70   
     static String[] modeStrings = new String[]{"",
 71   
                                                "org.apache.axis.description.ParameterDesc.IN",
 72   
                                                "org.apache.axis.description.ParameterDesc.OUT",
 73   
                                                "org.apache.axis.description.ParameterDesc.INOUT"};
 74   
     static HashMap styles = new HashMap();
 75   
     static HashMap uses = new HashMap();
 76   
 
 77   
     static {
 78  0
         styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT");
 79  0
         styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC");
 80  0
         styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE");
 81  0
         styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED");
 82  0
         uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED");
 83  0
         uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL");
 84   
     }
 85   
 
 86   
     static int OPERDESC_PER_BLOCK = 10;
 87   
 
 88   
     /**
 89   
      * Constructor.
 90   
      */
 91  0
     protected J2eeStubWriter(J2eeEmitter emitter,
 92   
                              BindingEntry bEntry,
 93   
                              SymbolTable symbolTable) {
 94  0
         super(emitter, bEntry.getName() + "Stub", "stub");
 95  0
         this.bEntry = bEntry;
 96  0
         this.binding = bEntry.getBinding();
 97  0
         this.symbolTable = symbolTable;
 98   
     } // ctor
 99   
 
 100   
     /**
 101   
      * Returns "extends org.apache.axis.client.Stub ".
 102   
      */
 103  0
     protected String getExtendsText() {
 104  0
         return "extends org.apache.axis.client.Stub ";
 105   
     } // getExtendsText
 106   
 
 107   
     /**
 108   
      * Returns "implements <SEI> ".
 109   
      */
 110  0
     protected String getImplementsText() {
 111  0
         return "implements " + bEntry.getDynamicVar(J2eeBindingWriter.INTERFACE_NAME) + " ";
 112   
     } // getImplementsText
 113   
 
 114   
     /**
 115   
      * Write the body of the binding's stub file.
 116   
      */
 117  0
     protected void writeFileBody(PrintWriter pw) throws IOException {
 118  0
         PortType portType = binding.getPortType();
 119  0
         HashSet types = getTypesInPortType(portType);
 120  0
         boolean hasMIME = Utils.hasMIME(bEntry);
 121  0
         if (types.size() > 0 || hasMIME) {
 122  0
             pw.println("    private java.util.Vector cachedSerClasses = new java.util.Vector();");
 123  0
             pw.println("    private java.util.Vector cachedSerQNames = new java.util.Vector();");
 124  0
             pw.println("    private java.util.Vector cachedSerFactories = new java.util.Vector();");
 125  0
             pw.println("    private java.util.Vector cachedDeserFactories = new java.util.Vector();");
 126   
         }
 127  0
         pw.println();
 128  0
         pw.println("    static org.apache.axis.description.OperationDesc [] _operations;");
 129  0
         pw.println();
 130  0
         writeOperationMap(pw);
 131  0
         pw.println();
 132  0
         pw.println("    public " + className + "() throws org.apache.axis.AxisFault {");
 133  0
         pw.println("         this(null);");
 134  0
         pw.println("    }");
 135  0
         pw.println();
 136  0
         pw.println("    public " + className + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
 137  0
         pw.println("         this(service);");
 138  0
         pw.println("         super.cachedEndpoint = endpointURL;");
 139  0
         pw.println("    }");
 140  0
         pw.println();
 141  0
         pw.println("    public " + className + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
 142  0
         pw.println("        if (service == null) {");
 143  0
         pw.println("            super.service = new org.apache.axis.client.Service();");
 144  0
         pw.println("        } else {");
 145  0
         pw.println("            super.service = service;");
 146  0
         pw.println("        }");
 147  0
         pw
 148   
                 .println("        ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\""
 149   
                         + emitter.getTypeMappingVersion() + "\");");
 150  0
         List deferredBindings = new ArrayList();
 151   
         // keep track of how many type mappings we write out
 152  0
         int typeMappingCount = 0;
 153  0
         if (types.size() > 0) {
 154  0
             Iterator it = types.iterator();
 155  0
             while (it.hasNext()) {
 156  0
                 TypeEntry type = (TypeEntry) it.next();
 157   
                 // Note this same check is repeated in JavaDeployWriter.
 158  0
                 if (!Utils.shouldEmit(type)) {
 159  0
                     continue;
 160   
                 }
 161   
 
 162   
                 // Write out serializer declarations
 163  0
                 if (typeMappingCount == 0) {
 164  0
                     writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
 165   
                 }
 166   
 
 167   
                 // write the type mapping for this type
 168  0
                 writeSerializationInit(pw, type);
 169   
 
 170   
                 // increase the number of type mappings count
 171  0
                 typeMappingCount++;
 172   
             }
 173   
         }
 174   
         // We need to write out the MIME mapping, even if we don't have
 175   
         // any type mappings
 176  0
         if (typeMappingCount == 0 && hasMIME) {
 177  0
             writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
 178  0
             typeMappingCount++;
 179   
         }
 180  0
         pw.println("    }");
 181  0
         pw.println();
 182  0
         pw.println("    private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
 183  0
         pw.println("        try {");
 184  0
         pw.println("            org.apache.axis.client.Call _call =");
 185  0
         pw.println("                    (org.apache.axis.client.Call) super.service.createCall();");
 186  0
         pw.println("            if (super.maintainSessionSet) {");
 187  0
         pw.println("                _call.setMaintainSession(super.maintainSession);");
 188  0
         pw.println("            }");
 189  0
         pw.println("            if (super.cachedUsername != null) {");
 190  0
         pw.println("                _call.setUsername(super.cachedUsername);");
 191  0
         pw.println("            }");
 192  0
         pw.println("            if (super.cachedPassword != null) {");
 193  0
         pw.println("                _call.setPassword(super.cachedPassword);");
 194  0
         pw.println("            }");
 195  0
         pw.println("            if (super.cachedEndpoint != null) {");
 196  0
         pw.println("                _call.setTargetEndpointAddress(super.cachedEndpoint);");
 197  0
         pw.println("            }");
 198  0
         pw.println("            if (super.cachedTimeout != null) {");
 199  0
         pw.println("                _call.setTimeout(super.cachedTimeout);");
 200  0
         pw.println("            }");
 201  0
         pw.println("            if (super.cachedPortName != null) {");
 202  0
         pw.println("                _call.setPortName(super.cachedPortName);");
 203  0
         pw.println("            }");
 204  0
         pw.println("            java.util.Enumeration keys = super.cachedProperties.keys();");
 205  0
         pw.println("            while (keys.hasMoreElements()) {");
 206  0
         pw.println("                java.lang.String key = (java.lang.String) keys.nextElement();");
 207  0
         pw.println("                _call.setProperty(key, super.cachedProperties.get(key));");
 208  0
         pw.println("            }");
 209  0
         if (typeMappingCount > 0) {
 210  0
             pw.println("            // " + Messages.getMessage("typeMap00"));
 211  0
             pw.println("            // " + Messages.getMessage("typeMap01"));
 212  0
             pw.println("            // " + Messages.getMessage("typeMap02"));
 213  0
             pw.println("            // " + Messages.getMessage("typeMap03"));
 214  0
             pw.println("            // " + Messages.getMessage("typeMap04"));
 215  0
             pw.println("            synchronized (this) {");
 216  0
             pw.println("                if (firstCall()) {");
 217   
 
 218   
             // Hack alert - we need to establish the encoding style before we register type mappings due
 219   
             // to the fact that TypeMappings key off of encoding style
 220  0
             pw.println("                    // "
 221   
                     + Messages.getMessage("mustSetStyle"));
 222  0
             if (bEntry.hasLiteral()) {
 223  0
                 pw.println("                    _call.setEncodingStyle(null);");
 224   
             } else {
 225  0
                 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
 226  0
                 while (iterator.hasNext()) {
 227  0
                     Object obj = iterator.next();
 228  0
                     if (obj instanceof SOAPBinding) {
 229  0
                         pw.println("                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
 230  0
                         pw.println("                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
 231  0
                     } else if (obj instanceof UnknownExtensibilityElement) {
 232   
                         //TODO: After WSDL4J supports soap12, change this code
 233  0
                         UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
 234  0
                         QName name = unkElement.getElementType();
 235  0
                         if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
 236   
                                 name.getLocalPart().equals("binding")) {
 237  0
                             pw.println("                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
 238  0
                             pw.println("                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);");
 239   
                         }
 240   
                     }
 241   
                 }
 242   
             }
 243  0
             pw.println("                    for (int i = 0; i < cachedSerFactories.size(); ++i) {");
 244  0
             pw.println("                        java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);");
 245  0
             pw.println("                        javax.xml.namespace.QName qName =");
 246  0
             pw.println("                                (javax.xml.namespace.QName) cachedSerQNames.get(i);");
 247  0
             pw.println("                        java.lang.Class sf = (java.lang.Class)");
 248  0
             pw.println("                                 cachedSerFactories.get(i);");
 249  0
             pw.println("                        java.lang.Class df = (java.lang.Class)");
 250  0
             pw.println("                                 cachedDeserFactories.get(i);");
 251  0
             pw.println("                        _call.registerTypeMapping(cls, qName, sf, df, false);");
 252  0
             pw.println("                    }");
 253  0
             pw.println("                }");
 254  0
             pw.println("            }");
 255   
         }
 256  0
         pw.println("            return _call;");
 257  0
         pw.println("        }");
 258  0
         pw.println("        catch (java.lang.Throwable t) {");
 259  0
         pw.println("            throw new org.apache.axis.AxisFault(\""
 260   
                 + Messages.getMessage("badCall01") + "\", t);");
 261  0
         pw.println("        }");
 262  0
         pw.println("    }");
 263  0
         pw.println();
 264  0
         List operations = binding.getBindingOperations();
 265  0
         for (int i = 0; i < operations.size(); ++i) {
 266  0
             BindingOperation operation = (BindingOperation) operations.get(i);
 267  0
             Parameters parameters =
 268   
                     bEntry.getParameters(operation.getOperation());
 269   
 
 270   
             // Get the soapAction from the <soap:operation>
 271  0
             String soapAction = "";
 272  0
             String opStyle = null;
 273  0
             Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
 274  0
             for (; operationExtensibilityIterator.hasNext();) {
 275  0
                 Object obj = operationExtensibilityIterator.next();
 276  0
                 if (obj instanceof SOAPOperation) {
 277  0
                     soapAction = ((SOAPOperation) obj).getSoapActionURI();
 278  0
                     opStyle = ((SOAPOperation) obj).getStyle();
 279  0
                     break;
 280  0
                 } else if (obj instanceof UnknownExtensibilityElement) {
 281   
                     //TODO: After WSDL4J supports soap12, change this code
 282  0
                     UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
 283  0
                     QName name = unkElement.getElementType();
 284  0
                     if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
 285   
                             name.getLocalPart().equals("operation")) {
 286  0
                         if (unkElement.getElement().getAttribute("soapAction") != null) {
 287  0
                             soapAction = unkElement.getElement().getAttribute("soapAction");
 288   
                         }
 289  0
                         opStyle = unkElement.getElement().getAttribute("style");
 290   
                     }
 291   
                 }
 292   
             }
 293  0
             Operation ptOperation = operation.getOperation();
 294  0
             OperationType type = ptOperation.getStyle();
 295   
 
 296   
             // These operation types are not supported.  The signature
 297   
             // will be a string stating that fact.
 298  0
             if (type == OperationType.NOTIFICATION
 299   
                     || type == OperationType.SOLICIT_RESPONSE) {
 300  0
                 pw.println(parameters.signature);
 301  0
                 pw.println();
 302   
             } else {
 303  0
                 writeOperation(pw, operation, parameters, soapAction, opStyle,
 304   
                         type == OperationType.ONE_WAY, i);
 305   
             }
 306   
         }
 307   
     } // writeFileBody
 308   
 
 309  0
     private void writeOperationMap(PrintWriter pw) {
 310  0
         List operations = binding.getBindingOperations();
 311  0
         pw.println("    static {");
 312  0
         pw.println("        _operations = new org.apache.axis.description.OperationDesc[" +
 313   
                 operations.size() + "];");
 314  0
         for (int j = 0, k = 0; j < operations.size(); ++j) {
 315  0
             if ((j % OPERDESC_PER_BLOCK) == 0) {
 316  0
                 k++;
 317  0
                 pw.println("        _initOperationDesc" + k + "();");
 318   
             }
 319   
         }
 320  0
         for (int i = 0, k = 0; i < operations.size(); ++i) {
 321  0
             if ((i % OPERDESC_PER_BLOCK) == 0) {
 322  0
                 k++;
 323  0
                 pw.println("    }\n");
 324  0
                 pw.println("    private static void _initOperationDesc" + k + "(){");
 325  0
                 pw.println("        org.apache.axis.description.OperationDesc oper;");
 326   
             }
 327  0
             BindingOperation operation = (BindingOperation) operations.get(i);
 328  0
             Parameters parameters =
 329   
                     bEntry.getParameters(operation.getOperation());
 330   
 
 331   
             // Get the soapAction from the <soap:operation>
 332  0
             String opStyle = null;
 333  0
             Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
 334  0
             for (; operationExtensibilityIterator.hasNext();) {
 335  0
                 Object obj = operationExtensibilityIterator.next();
 336  0
                 if (obj instanceof SOAPOperation) {
 337  0
                     opStyle = ((SOAPOperation) obj).getStyle();
 338  0
                     break;
 339  0
                 } else if (obj instanceof UnknownExtensibilityElement) {
 340   
                     //TODO: After WSDL4J supports soap12, change this code
 341  0
                     UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
 342  0
                     QName name = unkElement.getElementType();
 343  0
                     if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
 344   
                             name.getLocalPart().equals("operation")) {
 345  0
                         opStyle = unkElement.getElement().getAttribute("style");
 346   
                     }
 347   
                 }
 348   
             }
 349  0
             Operation ptOperation = operation.getOperation();
 350  0
             OperationType type = ptOperation.getStyle();
 351   
 
 352   
             // These operation types are not supported.  The signature
 353   
             // will be a string stating that fact.
 354  0
             if (type == OperationType.NOTIFICATION
 355   
                     || type == OperationType.SOLICIT_RESPONSE) {
 356  0
                 pw.println(parameters.signature);
 357  0
                 pw.println();
 358   
             }
 359  0
             String operName = operation.getName();
 360  0
             String indent = "        ";
 361  0
             pw.println(indent + "oper = new org.apache.axis.description.OperationDesc();");
 362  0
             pw.println(indent + "oper.setName(\"" + operName + "\");");
 363   
 
 364   
             // loop over paramters and set up in/out params
 365  0
             for (int j = 0; j < parameters.list.size(); ++j) {
 366  0
                 Parameter p = (Parameter) parameters.list.get(j);
 367   
 
 368   
                 // Get the QName representing the parameter type
 369  0
                 QName paramType = Utils.getXSIType(p);
 370   
 
 371   
                 // Set the javaType to the name of the type
 372  0
                 String javaType = null;
 373  0
                 if (p.getMIMEInfo() != null) {
 374  0
                     MimeInfo mimeInfo = p.getMIMEInfo();
 375  0
                     javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions() + ".class, ";
 376   
                 } else {
 377  0
                     javaType = p.getType().getName();
 378  0
                     if (javaType != null) {
 379  0
                         javaType += ".class, ";
 380   
                     } else {
 381  0
                         javaType = "null, ";
 382   
                     }
 383   
                 }
 384   
 
 385   
                 // Get the text representing newing a QName for the name and type
 386  0
                 String paramNameText = Utils.getNewQName(p.getQName());
 387  0
                 String paramTypeText = Utils.getNewQName(paramType);
 388   
 
 389   
                 // Generate the addParameter call with the
 390   
                 // name qname, typeQName, optional javaType, and mode
 391  0
                 boolean isInHeader = p.isInHeader();
 392  0
                 boolean isOutHeader = p.isOutHeader();
 393  0
                 pw.println("        oper.addParameter(" + paramNameText
 394   
                         + ", " + paramTypeText + ", "
 395   
                         + javaType + modeStrings[p.getMode()]
 396   
                         + ", " + isInHeader + ", " + isOutHeader + ");");
 397   
             }
 398   
             // set output type
 399  0
             if (parameters.returnParam != null) {
 400   
                 // Get the QName for the return Type
 401  0
                 QName returnType = Utils.getXSIType(parameters.returnParam);
 402   
 
 403   
                 // Get the javaType
 404  0
                 String javaType = null;
 405  0
                 if (parameters.returnParam.getMIMEInfo() != null) {
 406  0
                     MimeInfo mimeInfo = parameters.returnParam.getMIMEInfo();
 407  0
                     javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions();
 408   
                 } else {
 409  0
                     javaType = parameters.returnParam.getType().getName();
 410   
                 }
 411  0
                 if (javaType == null) {
 412  0
                     javaType = "";
 413   
                 } else {
 414  0
                     javaType = javaType + ".class";
 415   
                 }
 416  0
                 pw.println("        oper.setReturnType(" +
 417   
                         Utils.getNewQName(returnType) + ");");
 418  0
                 pw.println("        oper.setReturnClass("
 419   
                         + javaType + ");");
 420  0
                 QName returnQName = parameters.returnParam.getQName();
 421  0
                 if (returnQName != null) {
 422  0
                     pw.println("        oper.setReturnQName(" +
 423   
                             Utils.getNewQName(returnQName) + ");");
 424   
                 }
 425  0
                 if (parameters.returnParam.isOutHeader()) {
 426  0
                     pw.println("        oper.setReturnHeader(true);");
 427   
                 }
 428   
             } else {
 429  0
                 pw.println("        oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
 430   
             }
 431  0
             boolean hasMIME = Utils.hasMIME(bEntry, operation);
 432  0
             Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
 433  0
             Use use = bEntry.getInputBodyType(operation.getOperation());
 434  0
             if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
 435  0
                 style = Style.WRAPPED;
 436   
             }
 437  0
             if (!hasMIME) {
 438  0
                 pw.println("        oper.setStyle(" + styles.get(style) + ");");
 439  0
                 pw.println("        oper.setUse(" + uses.get(use) + ");");
 440   
             }
 441   
 
 442   
             // Register fault/exception information for this operation
 443  0
             writeFaultInfo(pw, operation);
 444  0
             pw.println(indent + "_operations[" + i + "] = oper;");
 445  0
             pw.println("");
 446   
         }
 447  0
         pw.println("    }");
 448   
     }
 449   
 
 450   
     /**
 451   
      * This method returns a set of all the TypeEntry in a given PortType.
 452   
      * The elements of the returned HashSet are Types.
 453   
      */
 454  0
     private HashSet getTypesInPortType(PortType portType) {
 455  0
         HashSet types = new HashSet();
 456  0
         HashSet firstPassTypes = new HashSet();
 457   
 
 458   
         // Get all the types from all the operations
 459  0
         List operations = portType.getOperations();
 460  0
         for (int i = 0; i < operations.size(); ++i) {
 461  0
             Operation op = (Operation) operations.get(i);
 462  0
             firstPassTypes.addAll(getTypesInOperation(op));
 463   
         }
 464   
 
 465   
         // Add all the types nested and derived from the types
 466   
         // in the first pass.
 467  0
         Iterator i = firstPassTypes.iterator();
 468  0
         while (i.hasNext()) {
 469  0
             TypeEntry type = (TypeEntry) i.next();
 470  0
             if (!types.contains(type)) {
 471  0
                 types.add(type);
 472  0
                 types.addAll(type.getNestedTypes(symbolTable, true));
 473   
             }
 474   
         }
 475  0
         if (emitter.isAllWanted()) {
 476  0
             HashMap rawSymbolTable = symbolTable.getHashMap();
 477  0
             for (Iterator j = rawSymbolTable.values().iterator(); j.hasNext();) {
 478  0
                 Vector typeVector = (Vector) j.next();
 479  0
                 for (Iterator k = typeVector.iterator(); k.hasNext();) {
 480  0
                     Object symbol = k.next();
 481  0
                     if (symbol instanceof DefinedType) {
 482  0
                         TypeEntry type = (TypeEntry) symbol;
 483  0
                         if (!types.contains(type)) {
 484  0
                             types.add(type);
 485   
                         }
 486   
                     }
 487   
                 }
 488   
             }
 489   
         }
 490  0
         return types;
 491   
     } // getTypesInPortType
 492   
 
 493   
     /**
 494   
      * This method returns a set of all the TypeEntry in a given Operation.
 495   
      * The elements of the returned HashSet are TypeEntry.
 496   
      */
 497  0
     private HashSet getTypesInOperation(Operation operation) {
 498  0
         HashSet types = new HashSet();
 499  0
         Vector v = new Vector();
 500  0
         Parameters params = bEntry.getParameters(operation);
 501   
 
 502   
         // Loop over parameter types for this operation
 503  0
         for (int i = 0; i < params.list.size(); i++) {
 504  0
             Parameter p = (Parameter) params.list.get(i);
 505  0
             v.add(p.getType());
 506   
         }
 507   
 
 508   
         // Add the return type
 509  0
         if (params.returnParam != null)
 510  0
             v.add(params.returnParam.getType());
 511   
 
 512   
         // Collect all the types in faults
 513  0
         Map faults = operation.getFaults();
 514  0
         if (faults != null) {
 515  0
             Iterator i = faults.values().iterator();
 516  0
             while (i.hasNext()) {
 517  0
                 Fault f = (Fault) i.next();
 518  0
                 partTypes(v,
 519   
                         f.getMessage().getOrderedParts(null));
 520   
             }
 521   
         }
 522   
         // Put all these types into a set.  This operation eliminates all duplicates.
 523  0
         for (int i = 0; i < v.size(); i++)
 524  0
             types.add(v.get(i));
 525  0
         return types;
 526   
     } // getTypesInOperation
 527   
 
 528   
     /**
 529   
      * This method returns a vector of TypeEntry for the parts.
 530   
      */
 531  0
     private void partTypes(Vector v, Collection parts) {
 532  0
         Iterator i = parts.iterator();
 533  0
         while (i.hasNext()) {
 534  0
             Part part = (Part) i.next();
 535  0
             QName qType = part.getTypeName();
 536  0
             if (qType != null) {
 537  0
                 v.add(symbolTable.getType(qType));
 538   
             } else {
 539  0
                 qType = part.getElementName();
 540  0
                 if (qType != null) {
 541  0
                     v.add(symbolTable.getElement(qType));
 542   
                 }
 543   
             }
 544   
         } // while
 545   
     } // partTypes
 546   
 
 547   
     /**
 548   
      * This function writes the regsiterFaultInfo API calls
 549   
      */
 550  0
     private void writeFaultInfo(PrintWriter pw, BindingOperation bindOp) {
 551  0
         Map faultMap = bEntry.getFaults();
 552   
         // Get the list of faults for this operation
 553  0
         ArrayList faults = (ArrayList) faultMap.get(bindOp);
 554   
 
 555   
         // check for no faults
 556  0
         if (faults == null) {
 557  0
             return;
 558   
         }
 559   
         // For each fault, register its information
 560  0
         for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) {
 561  0
             FaultInfo info = (FaultInfo) faultIt.next();
 562  0
             QName qname = info.getQName();
 563  0
             Message message = info.getMessage();
 564   
 
 565   
             // if no parts in fault, skip it!
 566  0
             if (qname == null) {
 567  0
                 continue;
 568   
             }
 569   
 
 570   
             // Get the Exception class name
 571  0
             String className = Utils.getFullExceptionName(message, symbolTable);
 572   
 
 573   
             // output the registration API call
 574  0
             pw.println("        oper.addFault(new org.apache.axis.description.FaultDesc(");
 575  0
             pw.println("                      " + Utils.getNewQName(qname) + ",");
 576  0
             pw.println("                      \"" + className + "\",");
 577  0
             pw.println("                      " + Utils.getNewQName(info.getXMLType()) + ", ");
 578  0
             pw.println("                      " + Utils.isFaultComplex(message, symbolTable));
 579  0
             pw.println("                     ));");
 580   
         }
 581   
     }
 582   
 
 583   
     /**
 584   
      * In the stub constructor, write the serializer code for the complex types.
 585   
      */
 586  0
     private void writeSerializationDecls(PrintWriter pw, boolean hasMIME,
 587   
                                          String namespace) {
 588  0
         pw.println("            java.lang.Class cls;");
 589  0
         pw.println("            javax.xml.namespace.QName qName;");
 590  0
         pw.println("            java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;");
 591  0
         pw.println("            java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;");
 592  0
         pw.println("            java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;");
 593  0
         pw.println("            java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;");
 594  0
         pw.println("            java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;");
 595  0
         pw.println("            java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;");
 596  0
         pw.println("            java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;");
 597  0
         pw.println("            java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;");
 598  0
         if (hasMIME) {
 599  0
             pw.println("            java.lang.Class mimesf = org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;");
 600  0
             pw.println("            java.lang.Class mimedf = org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;");
 601  0
             pw.println();
 602  0
             QName qname = new QName(namespace, "DataHandler");
 603  0
             pw.println("            qName = new javax.xml.namespace.QName(\""
 604   
                     + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
 605   
                     + "\");");
 606  0
             pw.println("            cachedSerQNames.add(qName);");
 607  0
             pw.println("            cls = javax.activation.DataHandler.class;");
 608  0
             pw.println("            cachedSerClasses.add(cls);");
 609  0
             pw.println("            cachedSerFactories.add(mimesf);");
 610  0
             pw.println("            cachedDeserFactories.add(mimedf);");
 611  0
             pw.println();
 612   
         }
 613   
     } // writeSerializationDecls
 614   
 
 615  0
     private void writeSerializationInit(PrintWriter pw, TypeEntry type) {
 616  0
         QName qname = type.getQName();
 617  0
         pw.println("            qName = new javax.xml.namespace.QName(\""
 618   
                 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
 619   
                 + "\");");
 620  0
         pw.println("            cachedSerQNames.add(qName);");
 621  0
         pw.println("            cls = " + type.getName() + ".class;");
 622  0
         pw.println("            cachedSerClasses.add(cls);");
 623  0
         if (type.getName().endsWith("[]")) {
 624  0
             pw.println("            cachedSerFactories.add(arraysf);");
 625  0
             pw.println("            cachedDeserFactories.add(arraydf);");
 626  0
         } else if (type.getNode() != null &&
 627   
                 Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null) {
 628  0
             pw.println("            cachedSerFactories.add(enumsf);");
 629  0
             pw.println("            cachedDeserFactories.add(enumdf);");
 630  0
         } else if (type.isSimpleType()) {
 631  0
             pw.println("            cachedSerFactories.add(simplesf);");
 632  0
             pw.println("            cachedDeserFactories.add(simpledf);");
 633  0
         } else if (type.getBaseType() != null) {
 634   
             // serializers are not required for types derived from base types
 635   
             // java type to qname mapping is anyway established by default
 636   
             // note that we have to add null to the serfactories vector to
 637   
             // keep the order of other entries, this is not going to screw
 638   
             // up because if type mapping returns null for a serialization
 639   
             // factory, it is assumed to be not-defined and the delegate
 640   
             // will be checked, the end delegate is DefaultTypeMappingImpl
 641   
             // that'll get it right with the base type name
 642  0
             pw.println("            cachedSerFactories.add(null);");
 643  0
             pw.println("            cachedDeserFactories.add(simpledf);");
 644   
         } else {
 645  0
             pw.println("            cachedSerFactories.add(beansf);");
 646  0
             pw.println("            cachedDeserFactories.add(beandf);");
 647   
         }
 648  0
         pw.println();
 649   
     } // writeSerializationInit
 650   
 
 651   
     /**
 652   
      * Write the stub code for the given operation.
 653   
      */
 654  0
     private void writeOperation(PrintWriter pw,
 655   
                                 BindingOperation operation,
 656   
                                 Parameters parms,
 657   
                                 String soapAction,
 658   
                                 String opStyle,
 659   
                                 boolean oneway,
 660   
                                 int opIndex) {
 661  0
         writeComment(pw, operation.getDocumentationElement(), true);
 662  0
         pw.println(parms.signature + " {");
 663  0
         pw.println("        if (super.cachedEndpoint == null) {");
 664  0
         pw.println("            throw new org.apache.axis.NoEndPointException();");
 665  0
         pw.println("        }");
 666  0
         pw.println("        org.apache.axis.client.Call _call = createCall();");
 667  0
         pw.println("        _call.setOperation(_operations[" + opIndex + "]);");
 668   
 
 669   
         // SoapAction
 670  0
         if (soapAction != null) {
 671  0
             pw.println("        _call.setUseSOAPAction(true);");
 672  0
             pw.println("        _call.setSOAPActionURI(\"" + soapAction + "\");");
 673   
         }
 674  0
         boolean hasMIME = Utils.hasMIME(bEntry, operation);
 675   
 
 676   
         // Encoding: literal or encoded use.
 677  0
         Use use = bEntry.getInputBodyType(operation.getOperation());
 678  0
         if (use == Use.LITERAL) {
 679   
             // Turn off encoding
 680  0
             pw.println("        _call.setEncodingStyle(null);");
 681   
             // turn off XSI types
 682  0
             pw.println("        _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
 683   
         }
 684  0
         if (hasMIME || use == Use.LITERAL) {
 685   
             // If it is literal, turn off multirefs.
 686   
             //
 687   
             // If there are any MIME types, turn off multirefs.
 688   
             // I don't know enough about the guts to know why
 689   
             // attachments don't work with multirefs, but they don't.
 690  0
             pw.println("        _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
 691   
         }
 692  0
         Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
 693  0
         if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
 694  0
             style = Style.WRAPPED;
 695   
         }
 696  0
         Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
 697  0
         while (iterator.hasNext()) {
 698  0
             Object obj = iterator.next();
 699  0
             if (obj instanceof SOAPBinding) {
 700  0
                 pw.println("        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
 701  0
             } else if (obj instanceof UnknownExtensibilityElement) {
 702   
                 //TODO: After WSDL4J supports soap12, change this code
 703  0
                 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
 704  0
                 QName name = unkElement.getElementType();
 705  0
                 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
 706   
                         name.getLocalPart().equals("binding")) {
 707  0
                     pw.println("        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
 708   
                 }
 709   
             }
 710   
         }
 711   
         
 712   
         // Operation name
 713  0
         if (style == Style.WRAPPED) {
 714   
             // We need to make sure the operation name, which is what we
 715   
             // wrap the elements in, matches the Qname of the parameter
 716   
             // element.
 717  0
             Map partsMap = operation.getOperation().getInput().getMessage().getParts();
 718  0
             Part p = (Part) partsMap.values().iterator().next();
 719  0
             QName q = p.getElementName();
 720  0
             pw.println("        _call.setOperationName(" + Utils.getNewQName(q) + ");");
 721   
         } else {
 722  0
             QName elementQName =
 723   
                     Utils.getOperationQName(operation, bEntry, symbolTable);
 724  0
             if (elementQName != null) {
 725  0
                 pw.println("        _call.setOperationName(" +
 726   
                         Utils.getNewQName(elementQName) + ");");
 727   
             }
 728   
         }
 729  0
         pw.println();
 730   
 
 731   
         // Set the headers
 732  0
         pw.println("        setRequestHeaders(_call);");
 733   
         
 734   
         // Set the attachments
 735  0
         pw.println("        setAttachments(_call);");
 736   
         
 737   
         // Set DIME flag if needed 
 738  0
         if (bEntry.isOperationDIME(operation.getOperation().getName())) {
 739  0
             pw.println("        _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);");
 740   
         }
 741   
 
 742   
         // Invoke the operation
 743  0
         if (oneway) {
 744  0
             pw.print("        _call.invokeOneWay(");
 745   
         } else {
 746  0
             pw.print(" try {");
 747  0
             pw.print("        java.lang.Object _resp = _call.invoke(");
 748   
         }
 749  0
         pw.print("new java.lang.Object[] {");
 750  0
         writeParameters(pw, parms);
 751  0
         pw.println("});");
 752  0
         pw.println();
 753  0
         if (!oneway) {
 754  0
             writeResponseHandling(pw, parms);
 755   
         }
 756  0
         pw.println("    }");
 757  0
         pw.println();
 758   
     } // writeOperation
 759   
 
 760  0
     private void writeParameters(PrintWriter pw, Parameters parms) {
 761   
         // Write the input and inout parameter list
 762  0
         boolean needComma = false;
 763  0
         for (int i = 0; i < parms.list.size(); ++i) {
 764  0
             Parameter p = (Parameter) parms.list.get(i);
 765  0
             if (p.getMode() != Parameter.OUT) {
 766  0
                 if (needComma) {
 767  0
                     pw.print(", ");
 768   
                 } else {
 769  0
                     needComma = true;
 770   
                 }
 771  0
                 String javifiedName = Utils.xmlNameToJava(p.getName());
 772  0
                 if (p.getMode() != Parameter.IN) {
 773  0
                     javifiedName += ".value";
 774   
                 }
 775  0
                 if (p.getMIMEInfo() == null) {
 776  0
                     javifiedName = Utils.wrapPrimitiveType(p.getType(), javifiedName);
 777   
                 }
 778  0
                 pw.print(javifiedName);
 779   
             }
 780   
         }
 781   
     } // writeParamters
 782   
 
 783  0
     private void writeResponseHandling(PrintWriter pw, Parameters parms) {
 784  0
         pw.println("        if (_resp instanceof java.rmi.RemoteException) {");
 785  0
         pw.println("            throw (java.rmi.RemoteException)_resp;");
 786  0
         pw.println("        }");
 787  0
         int allOuts = parms.outputs + parms.inouts;
 788  0
         if (allOuts > 0) {
 789  0
             pw.println("        else {");
 790  0
             pw.println("            extractAttachments(_call);");
 791  0
             if (allOuts == 1) {
 792  0
                 if (parms.returnParam != null) {
 793  0
                     writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
 794   
                 } else {
 795   
                     // The resp object must go into a holder
 796  0
                     int i = 0;
 797  0
                     Parameter p = (Parameter) parms.list.get(i);
 798  0
                     while (p.getMode() == Parameter.IN) {
 799  0
                         p = (Parameter) parms.list.get(++i);
 800   
                     }
 801  0
                     String javifiedName = Utils.xmlNameToJava(p.getName());
 802  0
                     String qnameName = Utils.getNewQName(p.getQName());
 803  0
                     pw.println("            java.util.Map _output;");
 804  0
                     pw.println("            _output = _call.getOutputParams();");
 805  0
                     writeOutputAssign(pw, javifiedName + ".value = ",
 806   
                             p,
 807   
                             "_output.get(" + qnameName + ")");
 808   
                 }
 809   
             } else {
 810   
                 // There is more than 1 output.  Get the outputs from getOutputParams.
 811  0
                 pw.println("            java.util.Map _output;");
 812  0
                 pw.println("            _output = _call.getOutputParams();");
 813  0
                 for (int i = 0; i < parms.list.size(); ++i) {
 814  0
                     Parameter p = (Parameter) parms.list.get(i);
 815  0
                     String javifiedName = Utils.xmlNameToJava(p.getName());
 816  0
                     String qnameName = Utils.getNewQName(p.getQName());
 817  0
                     if (p.getMode() != Parameter.IN) {
 818  0
                         writeOutputAssign(pw, javifiedName + ".value = ",
 819   
                                 p,
 820   
                                 "_output.get(" + qnameName + ")");
 821   
                     }
 822   
                 }
 823  0
                 if (parms.returnParam != null) {
 824  0
                     writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
 825   
                 }
 826   
             }
 827  0
             pw.println("        }");
 828   
         } else {
 829  0
             pw.println("        extractAttachments(_call);");
 830   
         }
 831   
         // End catch
 832   
         // Get faults
 833  0
         Map faults = parms.faults;
 834   
         // Get fauls of signature
 835  0
         String[] throwsSig = parms.signature.split("throws");
 836  0
         List exceptionsThrowsList = new ArrayList();
 837  0
         if (throwsSig != null && throwsSig.length > 1) {
 838  0
             String[] thrExcep = throwsSig[1].split(",");
 839  0
             for (int i = 0; i < thrExcep.length; i++) {
 840  0
                 exceptionsThrowsList.add(thrExcep[i]);
 841   
             }
 842   
         }
 843  0
         pw
 844   
                 .println("  } catch (org.apache.axis.AxisFault axisFaultException) {");
 845  0
         if (faults != null && faults.size() > 0) {
 846  0
             pw.println("    if (axisFaultException.detail != null) {");
 847  0
             for (Iterator faultIt = exceptionsThrowsList.iterator(); faultIt
 848   
                     .hasNext();) {
 849  0
                 String exceptionFullName = (String) faultIt.next();
 850  0
                 pw.println("        if (axisFaultException.detail instanceof "
 851   
                         + exceptionFullName + ") {");
 852  0
                 pw.println("              throw (" + exceptionFullName
 853   
                         + ") axisFaultException.detail;");
 854  0
                 pw.println("         }");
 855   
             }
 856  0
             pw.println("   }");
 857   
         }
 858  0
         pw.println("  throw axisFaultException;");
 859  0
         pw.println("}");
 860   
     } // writeResponseHandling
 861   
 
 862   
     /**
 863   
      * writeOutputAssign
 864   
      *
 865   
      * @param target (either "return" or "something ="
 866   
      * @param type   (source TypeEntry)
 867   
      * @param source (source String)
 868   
      */
 869  0
     private void writeOutputAssign(PrintWriter pw, String target,
 870   
                                    Parameter param,
 871   
                                    String source) {
 872  0
         TypeEntry type = param.getType();
 873  0
         if ((type != null) && (type.getName() != null)) {
 874  0
             String typeName = type.getName();
 875  0
             if (param.isOmittable()) {
 876  0
                 typeName = Utils.getWrapperType(type.getName());
 877   
             }
 878   
 
 879   
             // Try casting the output to the expected output.
 880   
             // If that fails, use JavaUtils.convert()
 881  0
             pw.println("            try {");
 882  0
             pw.println("                " + target
 883   
                     + Utils.getResponseString(param, source));
 884  0
             pw.println("            } catch (java.lang.Exception _exception) {");
 885  0
             pw.println("                " + target
 886   
                     + Utils.getResponseString(param,
 887   
                             "org.apache.axis.utils.JavaUtils.convert(" +
 888   
                     source + ", " + typeName + ".class)"));
 889  0
             pw.println("            }");
 890   
         } else {
 891  0
             pw.println("              " + target
 892   
                     + Utils.getResponseString(param, source));
 893   
         }
 894   
     }
 895   
 
 896   
 }
 897